package game;

import java.awt.Font;
import java.awt.FontFormatException;
import java.io.IOException;
import java.io.InputStream;
import org.newdawn.slick.TrueTypeFont;
import org.newdawn.slick.util.ResourceLoader;

/**
 *
 * @author Luan
 */
public class FontLoader {
    
    public static TrueTypeFont MAIN_TITLE, TITLE, MENU, TEXT_SMALL, TEXT_SMALLEST, TEXT, TEXT_BOLD, TEXT_BIG;
    public static String PATH;
    
    public static final String TITLE_NAME = "title.ttf", TEXT_NAME = "text.ttf";
    
    public static void load() {
        MAIN_TITLE = loadFont(TITLE_NAME, 45);
        TITLE = loadFont(TITLE_NAME, 40);
        MENU = loadFont(TITLE_NAME, 32);
        
        TEXT_SMALL = loadFont(TEXT_NAME, 14);
        TEXT_SMALLEST = loadFont(TEXT_NAME, 10);
        TEXT = loadFont(TEXT_NAME, 16);
        TEXT_BOLD = loadFont(TEXT_NAME, 16, 1);
        TEXT_BIG = loadFont(TEXT_NAME, 24);
    }
    
    public static TrueTypeFont loadFont(String nome, float size) {
        return loadFont(nome, size, 0);
    }
    
    public static TrueTypeFont loadFont(String nome, float size, int style) {
        try {
            InputStream inputStream = ResourceLoader.getResourceAsStream(PATH + "\\" + nome);
            Font awtFont = Font.createFont(Font.TRUETYPE_FONT, inputStream);
            awtFont = awtFont.deriveFont(style, size); //Set font style and size
            return new TrueTypeFont(awtFont, true);
        } catch (FontFormatException | IOException e) {
            System.err.println("There was an error while loading the font '" + nome + "': " + e.getLocalizedMessage());
            return null;
        }
    }
}
